

//
//  RadioHelp.m
//  NEWS_W_Y_S
//
//  Created by lanou3g on 15/10/15.
//  Copyright © 2015年 lanou3g.jake. All rights reserved.
//

#import "RadioHelp.h"
#import "UrlConnection.h"
#import "RadioModel.h"

static RadioHelp *rario = nil;

@implementation RadioHelp

+(RadioHelp *)shareRadioData{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (rario == nil) {
            rario = [[RadioHelp alloc] init];
        }
    });
    return rario;
}

-(void)requestWithUrl:(NSString *)url block:(void (^)(NSMutableArray *))block
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        
        [UrlConnection startConnection:url parmaters:nil connetionBlock:^(id responseObject) {
            if (responseObject) {
                NSArray *aray = responseObject[@"cList"];
                _dataArray = [[NSMutableArray alloc] init];
                for (NSDictionary *dic  in aray) {
                    RadioModel *model = [[RadioModel alloc] init];
                    [model setValuesForKeysWithDictionary:dic];
                    [self.dataArray addObject:model];
                }
                dispatch_async(dispatch_get_main_queue(), ^{
                    block(self.dataArray);
                    
                });
                
            }
        }];

    });
}

@end
